import { getParams } from '@/api/systemSetting/params-get'

export type SelectParamsType =
  | 'categoryTag'
  | 'violateType'
  | 'deptPositionType'
  | 'employmentStatus'
  | 'managePower'
  | 'positionLevel'
  | 'customLevel'
  | 'politicsStatus'

const optionsMap = new Map<SelectParamsType, any[]>()
const typeMap = new Map<SelectParamsType, number>([
  // 问题标签
  ['categoryTag', 51],
  // 违纪类型
  ['violateType', 52],
  // 职务分类
  ['deptPositionType', 54],
  // 任职状态
  ['employmentStatus', 55],
  // 管理权限
  ['managePower', 56],
  // 职务级别
  ['positionLevel', 57],
  // 自定义级别分类
  ['customLevel', 58],
  // 政治面貌
  ['politicsStatus', 39]
])

export const useOptions = (type: SelectParamsType) => {
  const getOptions = () => {
    return new Promise<any[]>((resolve) => {
      const data = optionsMap.get(type)
      if (data) {
        resolve(data)
        return
      }
      const id = typeMap.get(type)
      if (!id) return

      getParams(id).then((res) => {
        resolve(res.data)
        optionsMap.set(type, res.data)
      })
    })
  }

  return {
    getOptions
  }
}
